﻿using System;
using System.Windows.Media;
using nRoute.Components;

namespace Orktane.Components
{
    public class ConsoleColorValueConverter : ValueConverter<ConsoleColor, Brush>
    {

        public ConsoleColorValueConverter() : base() { }
           //: base((cc) => new SolidColorBrush(GetSolidColor(cc))) { } <-- Causes VerificationError, WTF!!?

        public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var _color = (ConsoleColor)value;
            return new SolidColorBrush(GetSolidColor(_color));
        }

        static Color GetSolidColor(ConsoleColor consoleColor)
        {
            switch (consoleColor)
            {
                case ConsoleColor.Black: return Colors.Black;
                case ConsoleColor.DarkBlue: return new Color() { A = Byte.MaxValue, R = 15, G = 14, B = 55};
                case ConsoleColor.DarkGreen: return new Color() { A = Byte.MaxValue, R = 0, G = 100, B = 0 };
                case ConsoleColor.DarkCyan: return new Color() { A = Byte.MaxValue, R = 0, G = 139, B = 139 };
                case ConsoleColor.DarkRed: return new Color() { A = Byte.MaxValue, R = 139, G = 0, B = 0 };
                case ConsoleColor.DarkMagenta: return new Color() { A = Byte.MaxValue, R = 139, G = 0, B = 139 };
                case ConsoleColor.DarkYellow: return new Color() { A = Byte.MaxValue, R = 179, G = 169, B = 0 };
                case ConsoleColor.Gray: return Colors.Gray;
                case ConsoleColor.DarkGray: return Colors.DarkGray;
                case ConsoleColor.Cyan: return Colors.Cyan;
                case ConsoleColor.Red: return Colors.Red;
                case ConsoleColor.Magenta: return Colors.Magenta;
                case ConsoleColor.Yellow: return Colors.Yellow;
                case ConsoleColor.White: return Colors.White;
            };
            return Colors.Blue;
        }

    }
}
